package cn.com.taurus.controller.major;

import cn.com.taurus.bean.FundManagerWebBean;
import cn.com.taurus.bean.FundWebBean;
import cn.com.taurus.bean.MyPurseWebBean;
import cn.com.taurus.biz.ClientOptionalBiz;
import cn.com.taurus.biz.FundManagerWebBeanBiz;
import cn.com.taurus.biz.FundWebBeanBiz;
import cn.com.taurus.controller.user.MyPurseController;
import cn.com.taurus.entity.Fund;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class FundWebController {

    @Autowired
    FundWebBeanBiz fundWebBeanBiz;
    @Autowired
    MyPurseController myPurseController;
    @Autowired
    ClientOptionalBiz clientOptionalBiz;




    @RequestMapping(value = "/Anonymous/fundWeb")
    public ModelAndView fundWeb(String fId){
        ModelAndView modelAndView = new ModelAndView();
        FundWebBean fundWebBean = fundWebBeanBiz.selectFundDataByFId(fId);
        //基金经理数量
        fundWebBean.setManagerFundCount(fundWebBeanBiz.selectManagerFundCountById(fundWebBean.getFmId()));

        //获取用户钱包的信息
        MyPurseWebBean myPurseWebBean = myPurseController.getMyPurseWebBean();

        modelAndView.setViewName("major/oneFund");
        modelAndView.addObject("fundData",fundWebBean);
        modelAndView.addObject("myPurseData",myPurseWebBean);

        //如果现在用户登录了 不为null
        if (myPurseWebBean != null){
            //查询当前用户的自选的基金
            List<Fund> list = clientOptionalBiz.selectClientOptionalFundByCId(myPurseWebBean.cId);
            for (Fund fund:list) {
                //判断用户是否自选过该基金
                if (fund.getfId().equals(fId)){
                    System.err.println("牛逼");
                    modelAndView.addObject("ifOptionalExist","true");
                }
            }
        }



        return modelAndView;
    }
}
